<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <meta name="viewport" content="width=device-width,minimum-scale=0.5,maximum-scale=1.0,initial-scale=1.0,user-scalable=no"
    />
    <link rel="stylesheet" href="./css/nregis.css" />
    <script src="./js/rem.js"></script>
    <script src="./js/zepto.js"></script>
    <script src="./layer_mobile/layer.js"></script>
    <script src="./js/touch.min.js"></script>
</head>

<body>
    <script type="text/html" id="code-wrapper-con">
        <div class="code-wrapper">
            <h5 class="code-title">请按照图形输入字母数字</h5>
            <div class="input-code-wrapper">
                <input type="text" class="picCode">
                <img src="./image/piccode.png" alt="" class="yzmget">
            </div>
            <div class="confirm2PhoneCode confirm-get-code">
                确定
            </div>
        </div>
    </script>
    <section>
        <div class="main">
            <div class="banner-wrap">
                <img src="./image/head1.png" class="head1" alt="">
                <img src="./image/head2.png" class="head2" alt="">
                <img src="./image/head3.png" class="head3" alt="">
                <img src="./image/head4.png" class="head4" alt="">
                <img src="./image/head5.png" class="head5" alt="">
                <img src="./image/head6.png" class="head6" alt="">
            </div>
            <div class="register-con">
                <ul>
                    <li class="recommend-person">
                        <span class="isnikename"></span>
                        <img src="./image/share.png" alt="">
                    </li>
                    <li><input class="messnum telnum" type="text" placeholder="请输入手机号"></li>
                    <li><input class="piccode" type="text" placeholder="请输入验证码">
                        <div style="width:2.1rem;" class="yzwraper getCode">获取验证码</div>
                    </li>
                    <li style="margin-bottom: 0;"><input class="messnum passwordnum" type="text" placeholder="请输入密码"></li>
                </ul>
                <div class="submit">
                    <img src="./image/regbtn.png" alt="">
                </div>

            </div>
            <div class="tabwrapper">
                <img src="./image/download.png" class="download" alt="">
                <img src="./image/a.png" class="userinfo" alt="">
                <img src="./image/c.png" class="argument" alt="">
            </div>
        </div>
    </section>





</body>
<script>
var alertIndex=null;
var sendCodeUrl='/api/send/sms';
var timer = null;
var tnum = 60;
var userid='';
var isClick = true;
var isCommit = true;
var get_invite_code=null;
$('.getCode').text('获取验证码');

function request(method,url,fun,data){
        // console.log(url);
        data=data||{};
        url+="?v="+new Date().getTime();
        $.ajax({
            type:method,
            url:url,
            data:data||{date:new Date().getTime()},
            success: function(msg){
                if(fun){
                    fun(msg);
                    }           
           },
            error: function () {
                            isCommit = true;
                            layer.open({content:'error',skin:'msg',time:2});
                        }
        })
        
    }
    var arr=location.href.split('?');

    var id=arr?arr[1]:0;

    request('get','/api/user/userdata',function(data){
        console.log(data)
        if(data.code==200){
            var user=data.data.cnt;
            if(id==0){
                get_invite_code=""
            }else{
                get_invite_code=user.invite_code; 
                userid=user.id;  
            }
            
            $('.isnikename').html(user.nick_name)
        }
    },{id:id})

    //获取手机验证码
            $('.getCode').on('tap', function () {

                if (!$('.telnum').val().trim()) {
                    
                    layer.open({content:'手机号不能为空',skin:'msg',time:2});
                    return false;
                }
                if(!(/^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test($('.telnum').val()))){
                    
                    layer.open({content:'请输入正确的手机号',skin:'msg',time:2});
                    return;
                }
                request('get',sendCodeUrl,function(data){
                    clearInterval(timer);
                    tnum = 60;
                    if (data.code == '200') {
                                layer.closeAll();
                                isClick = false;
                                layer.open({content:data.message,skin:'msg',time:2});
                                timer = setInterval(function () {
                                    if (tnum < 0) {
                                        clearInterval(timer);
                                        $('.getCode').text('获取验证码');
                                        isClick = true;
                                        return;
                                    }
                                    $('.getCode').text(tnum+'s');
                                    tnum--;
                                }, '1000');
                            } else if (data.code == '320') {
                                console.log(data.message);
                                
                                 layer.open({content:data.message,skin:'msg',time:2});
                                 
                                setTimeout(function(){
                                    location.href = 'newShareRegisfinsh.html';
                                },1000);
                                
                            } else {
                            
                               
                                layer.open({content:data.message,skin:'msg',time:2});
                                isClick = true;
                                $('.getCode').text('获取验证码');
                            }
                },{tel:$('.telnum').val().trim(),type:'reg'})
                return false;
            });



        //提交
        $('.submit').on('tap',function(){
            var pwd=$('.passwordnum').val().trim();
            var messcode=$('.piccode').val().trim();
            if (!$('.telnum').val().trim()) {
                    
                    layer.open({content:'手机号不能为空',skin:'msg',time:2});
                    return false;
                }
                if(!(/^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test($('.telnum').val()))){
                    
                    layer.open({content:'请输入正确的手机号',skin:'msg',time:2});
                    return;
                }
                if (!messcode) {
                    
                    layer.open({content:'手机号不能为空',skin:'msg',time:2});
                    return false;
                }
            if (isCommit) {
                    isCommit = false;
                    var pwd = $('.passwordnum').val();
                    request('post','/api/user/reg',function(data){
                        if (data.code == '200') {
                                // open('bindsucc.html','_self');
                                layer.open({content:data.message,skin:'msg',time:2});
                                location.href = 'newShareRegisfinsh.html';
                            } else {
                                isCommit = true;
                                layer.open({content:data.message,skin:'msg',time:2});
                            }
                    },{
                    	tel:$('.telnum').val().trim(),
                    	code:messcode,
                    	password:pwd,
                    	invite_code:get_invite_code
                    })
                }
            
        });

$('.download').on('tap',function(){
    location.href ='http://a.app.qq.com/o/simple.jsp?pkgname=gexinclient.gexin.com.gexinclient';
})
$('.userinfo').on('tap',function(){
    open('index.html?id='+userid,'_self');
})
$('.argument').on('tap',function(){
    open('protocol.html','_self');
})

</script>

</html>